#include<16f877a.h>
//#device ADC=10
#include<stdlib.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
//#use delay(clock=11592000)
#use delay(clock=16000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
unsigned int x_dir=0,y_dir=0,z_dir=0;


#define RF_A  PIN_D0
#define RF_B  PIN_D1
#define RF_C  PIN_D2
#define RF_D  PIN_D3
//#define MOT3 PIN_C2
//#define MOT4 PIN_C3
void main()
{
   //port_b_pullups(true);

   setup_port_A(ALL_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);
   output_d(0xff);
   while(1)
   {
      set_adc_channel(0);
      delay_us(20);
      y_dir=Read_ADC();
      //if(y_dir>=180)
      printf("%u\n\r",y_dir);
      if(y_dir<=60)
      {
      output_low(RF_A);
      //delay_ms(10);

      delay_ms(100);


      }
      //else if(y_dir<=158)
      else if(y_dir>=80)
      {
      output_low(RF_B);

      delay_ms(100);
      }
       //else if(y_dir>=159 && y_dir<=179)
      else //if(y_dir>=168 && y_dir<=174)
      {
      output_low(RF_C);
      delay_ms(100);
      }



      //printf("adc val=%u\n",y_dir);
      delay_ms(100);

output_d(0xff);

   }


}
